<template>
	<div id="handle-qq-login" class="ac">
		<template v-if="isLogin===true">
			<h1>登录成功,即将跳转</h1>
			<div class="">若没有自动跳转，请点击下方按钮回到首页</div>
		</template>
		<template v-else-if="isLogin===null">
			<div>登录中...</div>
		</template>
		<template v-else>
			<div>未登录</div>
		</template>
		<router-link to="/home"><el-button>返回首页</el-button></router-link>
	</div>
</template>

<script>
import QC from '@/assets/js/qc_jssdk.js';
import isPE from '@/utils/isPE.js'
import jsCookie from 'js-cookie'
export default {
	created() {
		if (QC.Login.check()) {
			QC.Login.getMe((openId, accessToken) => {
				//将openId, accessToken保存到localStorage中
				jsCookie.set('qq_openId',openId)
				jsCookie.set('qq_accessToken',accessToken)
				console.log("openId&&accessToken",openId&&accessToken)
				//删除登录标记,可删可不删
				QC.Login.signOut();
				if (isPE()) {
					//移动端直接跳转到指定参数的页面就行了
					this.$store.dispatch('user/refreshUser',user=>{
						if(user){
							this.isLogin=true
							this.$router.push(this.$route.query.rd);
						}else{
							this.isLogin=false
						}
					});
				} else {
					//pc直接关闭浏览器
					window.close();
					this.isLogin=true
					
				}
			});
		}else{
			this.isLogin=false
			console.log("isLogin=false")
		}
	},
	data(){
		return {
			isLogin:null
		}
	}
};
</script>

<style lang="scss">
	#handle-qq-login{
		position: fixed;
		height: 100%;
		width: 100%;
		top: 0;
		left: 0;
		background-color: #fff;
	}
</style>
